package com.sxd.bill.rela.extractor;

import java.util.Arrays;
import java.util.List;

import com.sxd.bill.common.enums.LabelNameEnum;
import com.sxd.bill.common.item.TextLabelItem;
import com.sxd.bill.rela.item.CoreRelationItem;

public class MultiDueTimeExtractor implements Extractable {
    private IntegrateExtractor integrateExtractor;
    private TemplateExtractor templateExtractor;

    public MultiDueTimeExtractor(List<String> specialTemplates) {
        this.integrateExtractor = new IntegrateExtractor(LabelNameEnum.DUE_TIME);
        this.templateExtractor = new TemplateExtractor();
        this.templateExtractor.addTemplates(specialTemplates);
    }

    @Override
    public String toString() {
        return String.format("%s(multiValLabel=%s,sepecialTemplates=[...])", this.getClass().getSimpleName(),
                this.integrateExtractor.getMultiValLabel());
    }

    @Override
    public List<CoreRelationItem> extract(TextLabelItem textLabelItem) {
        List<CoreRelationItem> items_1 = integrateExtractor.extract(textLabelItem);
        List<CoreRelationItem> items_2 = templateExtractor.extract(textLabelItem);
        return items_1.size() > 0 && items_2.size() > 0 ? items_2 : items_1;
    }

    public static MultiDueTimeExtractor ofDefault() {
        String[] templates = {
                "(?<!卖|买|托)【?(?<tradingDirection>出|收|买|卖)[.】：\\w]{0,3}${票据期限1}${承兑人1}和${票据期限2}票",
                "(?<!卖|买|托)【?(?<tradingDirection>出|收|买|卖)[.】：\\w]{0,3}${票据期限1}${承兑人1}\\s*或者${票据期限2}",
        };
        return new MultiDueTimeExtractor(Arrays.asList(templates));
    }

}
